<?php
/*
 *  supplier 供货商添加类
 *
 *  @param $c 一般是类名
 *  @param $a 一般是方法名
 */
class setStock extends Admin
{

    // private $tab = array( 'goodsEdit' => '宝贝编辑', 'goodsTask' => '宝贝任务');


    private $area = array('全中国','北京市','天津市','河北省','山西省','内蒙古',             //华北
                            '辽宁省','吉林省','黑龙江',                                           //东北
                            '上海市','江苏省','浙江省','安徽省','福建省','江西省','山东省',    //华东
                            '河南省','湖北省','湖南省','广东省','广西省','海南省',              //华中
                            '重庆市','四川省','贵州省','云南省','西藏省',                        //西南
                            '陕西省','甘肃省','青海省','宁夏','新疆',                            //西北
                            '香港','澳门','台湾');                                                 //特区

    public function index($c, $a)
    {

        $sql = "select  A.*,B.name,B.phone from xbl_stockPos as A,xbl_user as B where A.personId = B.id";


        $result = $this->Paged()->findSql($sql);

        $pager = $result['page'];
        $res = $result['result'];





        include $this->display($c);
    }

    public function  search($c, $a)
    {
        $this->table = 'bsInfo'; // 数据库表名

        $where = array(G('k') => G('v'));
        if ($key = G('key')) {
            $tmp = '';
            foreach ($where as $k => $v) {
                $tmp .= "{$k}='" . urldecode($v) . "' and ";
            }
            $where = $tmp ? ($tmp . "goodsNo ={$key} ") : '';
        }

        $result = $this->Paged()->findAll($where);
        $pager = $result['page'];
        $result = $result['result'];

        foreach ($result as $val) {
            $result[$key]['goodsStatus'] = $this->goodsStatus[$val['goodsStatus']];
        }

        include $this->display($c); // 加载模板
    }

    public function editStock($c, $a)
    {

        $stockNo = G('stockNo');

        $this->table = 'stockPos'; // 数据库表名
        $this->pk = 'stockNo';

        $result = $this->find(array('stockNo' => $stockNo)); // 查找数据

        $result['area'] = explode(',',$result['area']);
        array_filter($result['area']);

        $this->table = 'user';
        $this->pk = 'id';
        $res = $this->findAll(array('sid'=>8),null,'id,name');

        include $this->display($c); // 加载模板
    }

    public function addStock($c, $a)
    {

        $this->table = 'user'; // 数据库表名
        $res = $this->findAll(array('sid' =>8),null,'id,name'); // 查找数据

    //    print_r($res);

        include $this->display($c); // 加载模板
    }

    public function saveStockInfo($c, $a)
    {

        $this->table = 'stockPos'; // 数据库表名
        $this->pk = 'stockNo';

        $rows['area'] = '';

        foreach ($_POST as $key => $val) {

            if('area' == $key)
            {
                   foreach ( $_POST['area'] as $key1 => $val1 )
                   {
                       $rows['area'] = $rows['area'].$val1.',';
                   }
            }
            else
            {
                $rows[$key] = htmlspecialchars(trim($val));
            }
        }

        print_r($rows);


        if($result = $this->find(array('stockNo'=>$rows['stockNo'])))
        {
            print_r("124");
            $this->update(array('stockNo'=>$rows['stockNo']),$rows);
        }
        else
        {
            print_r("123");
            $this->create($rows);
        }



    }




}